from itsdangerous import TimedJSONWebSignatureSerializer
from django.conf import settings


def generate_access_token(openid):
    obj=TimedJSONWebSignatureSerializer(settings.SECRET_KEY,expires_in=300)

    dict={
        'openid':openid
    }
    return obj.dumps(dict).decode()


def check_access_token(access_token):
    """把access_token解密为openid"""
    obj=TimedJSONWebSignatureSerializer(settings.SECRET_KEY,expires_in=300)
    dict=obj.loads(access_token)
    return dict['openid']